﻿using System.ComponentModel;
using NUnit.Framework;

namespace ebcpatterns.wpf.tests
{
    [TestFixture]
    public class FlowCommandWithoutParameterTests
    {
        private FlowCommand sut;

        [SetUp]
        public void Setup() {
            sut = new FlowCommand();
        }

        [Test]
        public void Flow_Output_event_is_raised_on_command_execution() {
            var count = 0;
            sut.Process += () => count++;

            sut.Execute(null);

            Assert.That(count, Is.EqualTo(1));
        }

        [Test]
        public void Command_is_enabled() {
            Assert.That(new FlowCommand().CanExecute(null), Is.True);
        }

        [Test]
        public void Command_can_be_disabled_by_setting_bindable_property_IsEnabled() {
            sut.IsEnabled = false;
            Assert.That(sut.CanExecute(null), Is.False);
        }

        [Test]
        public void Changing_command_enabled_state_by_setting_IsEnabled_raises_PropertyChanged_event() {
            PropertyChangedEventArgs result = null;
            sut.PropertyChanged += (s, x) => result = x;

            sut.IsEnabled = false;

            Assert.That(result.PropertyName, Is.EqualTo("IsEnabled"));
        }

        [Test]
        public void Changing_command_enabled_state_by_setting_IsEnabled_raises_CanExecuteChanged_event() {
            var count = 0;
            sut.CanExecuteChanged += (s, x) => count++;

            sut.IsEnabled = false;

            Assert.That(count, Is.EqualTo(1));
        }

        [Test]
        public void Changing_command_enabled_state_by_setting_IsEnabled_is_persisted() {
            sut.IsEnabled = true;
            Assert.That(sut.IsEnabled, Is.True);
        }
    }
}